﻿using MediatR;
using WMS.API.Application.Command.StocktakingManagement.PendingOrder;
using WMS.Domain.Entities.StocktakingManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.StocktakingManagement
{
    /// <summary>
    /// 反填待盘点订单命令处理-xzc
    /// </summary>
    public class FindPendingOrdersCommandHandlers : IRequestHandler<FindPendingOrdersCommand, APIResult<List<PendingOrders>>>
    {
        private readonly IBaseRepository<PendingOrders> _pendingordersRepository;

        public FindPendingOrdersCommandHandlers(IBaseRepository<PendingOrders> pendingordersRepository)
        {
            _pendingordersRepository = pendingordersRepository;
        }

        public Task<APIResult<List<PendingOrders>>> Handle(FindPendingOrdersCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<PendingOrders>> result = new APIResult<List<PendingOrders>>("查询待盘点订单成功");

            result.Message = "查询待盘点订单成功";
            result.Code = ResultCode.Success;

            var list = _pendingordersRepository.GetAll(m => m.Id == request.Id).ToList();

            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
